package com.zui.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zui.common.domain.PageParam;
import com.zui.product.dao.BrandDao;
import com.zui.product.domain.entity.Brand;
import com.zui.product.domain.vo.brand.*;
import com.zui.product.service.BrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 品牌接口
 * @author 最光阴
 * @version 2021-05-05
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandDao, Brand> implements BrandService {

    /**
     * 品牌-添加
     *
     * @param addBrandVO
     * @return
     */
    @Override
    public void add(AddBrandVO addBrandVO) {
        Brand category = new Brand();
        BeanUtils.copyProperties(addBrandVO, category);
        save(category);
    }

    /**
     * 根据id查询品牌详情
     *
     * @param id
     * @return
     */
    public BrandVO get(String id) {
        Brand category = baseMapper.selectById(id);
        BrandVO result = new BrandVO();
        BeanUtils.copyProperties(category, result);
        return result;
    }

    /**
     * 分页查询品牌
     * @param param
     * @return
     */
    public PageInfo<BrandVO> page(PageParam<ListBrandVO> param) {
        PageHelper.startPage(param.getPageNo(), param.getPageSize());

        List<BrandVO> list = baseMapper.findList(param.getObj());

        return new PageInfo<>(list);
    }

    /**
     * 品牌-更新
     *
     * @param updateBrandVO
     * @return
     */
    @Override
    public void update(UpdateBrandVO updateBrandVO) {
        Brand category = new Brand();
        BeanUtils.copyProperties(updateBrandVO, category);
        updateById(category);
    }

    /**
     * 品牌-删除
     *
     * @param deleteBrandVO
     * @return
     */
    @Override
    public void delete(DeleteBrandVO deleteBrandVO) {
        // TODO ggg 判断是否有引用，有则不允许删除
        baseMapper.deleteById(deleteBrandVO.getId());
    }
}